import 'dart:convert';

import 'package:dio/dio.dart';
import 'dart:io';

/// 错误消息拦截器
class ErrorInterceptor extends Interceptor {
  factory ErrorInterceptor() {
    return _instance ??= ErrorInterceptor._();
  }

  ErrorInterceptor._();
  static ErrorInterceptor? _instance;

  @override
  void onResponse(
    Response<dynamic> response,
    ResponseInterceptorHandler handler,
  ) {
    final String dataStr = response.data.toString();
    try {
      //
      Map<dynamic, dynamic> dataJson;
      if (response.data is Map) {
        dataJson = response.data;
      } else {
        dataJson = json.decode(dataStr);
      }
      ////拦截报错信息

    } on DioError catch (e) {
      /// dio 报错

    }
    return super.onResponse(response, handler);
  }

  /*
   * error统一处理
   */

}
